package com.lzy.cloud.goods.service.GoodsServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.goods.dtos.CarMachineTypeDto;
import com.lzy.cloud.goods.entity.CarMachineType;
import com.lzy.cloud.goods.mapper.CarMachineTypeMapperExt;
import com.lzy.cloud.goods.service.CarMachineTypeService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by WIN7 on 2018/6/9.
 */
@Service
public class CarMachineTypeServiceImpl implements CarMachineTypeService{

    @Autowired
    CarMachineTypeMapperExt carMachineTypeMapperExt;

    @Override
    public Boolean add(CarMachineTypeDto carMachineTypeDto) {
        return carMachineTypeMapperExt.insertSelective(DozerUtils.map(carMachineTypeDto,CarMachineType.class))>0;
    }

    @Override
    public Boolean delById(Long id) {
        return carMachineTypeMapperExt.deleteByPrimaryKey(id)>0;
    }

    @Override
    public Boolean update(CarMachineTypeDto carMachineTypeDto) {
        return carMachineTypeMapperExt.updateByPrimaryKeySelective(DozerUtils.map(carMachineTypeDto,CarMachineType.class))>0;
    }

    @Override
    public PageInfo<CarMachineTypeDto> selectList(Pager pager, CarMachineTypeDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo<>(carMachineTypeMapperExt.selectList(dto));
    }

    @Override
    public CarMachineTypeDto selectById(Long id) {
        return DozerUtils.map(carMachineTypeMapperExt.selectByPrimaryKey(id),CarMachineTypeDto.class);
    }
}
